import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;


public class ShapesWindow extends JPanel implements ActionListener {
	private static final long serialVersionUID = 1L;

	private static ShapesWindow mShapesWindow = null;

	JButton rectButton;
	JButton lineButton; 
	JButton ellipseButton; 
	JButton triangleButton; 

	public ShapesWindow() {
		super();

		setLayout(new GridLayout(4,1)); 

		rectButton     = new JButton("Rectangle"); 
		lineButton     = new JButton ("Line"); 
		ellipseButton  = new JButton ("Ellipse");
		triangleButton = new JButton ("Triangle");

		rectButton.addActionListener(this); 
		lineButton.addActionListener(this); 
		ellipseButton.addActionListener(this); 
		triangleButton.addActionListener(this); 

		this.add(lineButton); 
		this.add(rectButton); 
		this.add(ellipseButton); 
		this.add(triangleButton); 
	}

	public static synchronized ShapesWindow Obj() {
		if (mShapesWindow == null) {
			mShapesWindow = new ShapesWindow();
		}
		return mShapesWindow;
	}

	// no cloning allowed
	public Object clone() throws CloneNotSupportedException {
		throw new CloneNotSupportedException();
	}	
	
    public void actionPerformed(ActionEvent e){
	PLShape.ShapeIdT id = PLShape.ShapeIdT.kMin;
	PLDebug.Warn("1");
    	if (e.getSource() == rectButton) {
    		id = PLShape.ShapeIdT.kRect;
    	} else if (e.getSource() == lineButton) {
    		id = PLShape.ShapeIdT.kLine;
	} else if (e.getSource() == ellipseButton) {
		id = PLShape.ShapeIdT.kEllipse;
    	} else if (e.getSource() == triangleButton) {
		id = PLShape.ShapeIdT.kTriangle;
    	}

	PLGuiInfo.Obj().SetCurShape(id);

	repaint();
	PLDebug.Warn("2");
    }
}
